#pragma once

#include "ProtocolConformance.h"

#include "ProtocolStateMachine.h"

namespace uml {

void ProtocolConformance::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    DirectedRelationship::fromJson(json, errorList);
    generalMachine_ = JsonSerializable::create<ProtocolStateMachine>(json.value("generalMachine"), errorList);

    specificMachine_ = JsonSerializable::create<ProtocolStateMachine>(json.value("specificMachine"), errorList);

}

void ProtocolConformance::toJson(QJsonObject& json) {
    DirectedRelationship::toJson(json);
    if (generalMachine_) {
        QJsonObject generalMachine_json;
        generalMachine_->toJson(generalMachine_json);
        json.insert("generalMachine", generalMachine_json);
    }
    if (specificMachine_) {
        QJsonObject specificMachine_json;
        specificMachine_->toJson(specificMachine_json);
        json.insert("specificMachine", specificMachine_json);
    }
}

/// <summary>
/// generalMachine getter
/// Specifies the ProtocolStateMachine to which the specific ProtocolStateMachine
/// conforms.
/// </summary>
shared_ptr<ProtocolStateMachine> ProtocolConformance::generalMachine() const {
    return generalMachine_;
}

/// <summary>
/// generalMachine setter
/// Specifies the ProtocolStateMachine to which the specific ProtocolStateMachine
/// conforms.
/// </summary>
void ProtocolConformance::setGeneralMachine(shared_ptr<ProtocolStateMachine> value) {
    generalMachine_ = value;
}

/// <summary>
/// specificMachine getter
/// Specifies the ProtocolStateMachine which conforms to the general
/// ProtocolStateMachine.
/// </summary>
shared_ptr<ProtocolStateMachine> ProtocolConformance::specificMachine() const {
    return specificMachine_;
}

/// <summary>
/// specificMachine setter
/// Specifies the ProtocolStateMachine which conforms to the general
/// ProtocolStateMachine.
/// </summary>
void ProtocolConformance::setSpecificMachine(shared_ptr<ProtocolStateMachine> value) {
    specificMachine_ = value;
}

} // namespace uml
